package org.fall.view.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author sprogFall
 * @since 2021/4/12 15:08
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResultEntity {
    public static final String SUCCESS = "SUCCESS";
    public static final String FAILED = "FAILED";

    /**
     * 数据域
     */
    private Object data;

    /**
     * 如果错误的话传递的消息
     */
    private String message;

    /**
     * 返回结果（SUCCESS / FAILED）
     */
    private String result;

    /**
     * 数据总量
     */
    private Long count;

    /**
     * 分页显示时使用 状态码
     */
    private Integer code;

    public ResultEntity(Object data, String message, String result) {
        this.data = data;
        this.message = message;
        this.result = result;
    }

    /**
     * 表示成功且不返回数据
     * @return 结果
     */
    public static ResultEntity successWithoutData(){
        return new ResultEntity(null,null, SUCCESS);
    }

    /**
     * 表示成功且返回数据
     * @param data 传递的数据
     * @return 结果
     */
    public static ResultEntity successWithData(Object data) {
        return new ResultEntity(data, null, SUCCESS);
    }

    public static ResultEntity successWithDataAndCount(Object data, Long count, Integer code) {
        ResultEntity resultEntity = new ResultEntity(data, null, SUCCESS);
        resultEntity.setCount(count);
        resultEntity.setCode(code);
        return resultEntity;
    }

    /**
     * 表示失败
     * @param message 传递的错误消息
     * @return 结果
     */
    public static ResultEntity failed(String message) {
        return new ResultEntity(null, message, FAILED);
    }

}

